home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / libraryUI.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  34.6 KB  |  1,325 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Copyright (C) 2000 Alias|Wavefront,
  18. // a division of Silicon Graphics Limited.
  19. //
  20. // The information in this file is provided for the exclusive use of the
  21. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  22. // and incorporate this code into other products for purposes authorized
  23. // by the Alias|Wavefront license agreement, without fee.
  24. //
  25. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  26. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  27. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  28. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  29. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  30. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  31. // PERFORMANCE OF THIS SOFTWARE.
  32. //
  33. //
  34. //  Alias|Wavefront Script File
  35. //  MODIFY THIS AT YOUR OWN RISK
  36. //
  37. //  Creation Date:  December 8/2000
  38. //  Author:         jdc rendering
  39. //
  40. // Description:
  41. //
  42. //        This file contains the procedures which implement a portable (can be
  43. //        used anywhere) user interface for viewing things on disk using a
  44. //        graphical layout. This file also contains the procedures used to
  45. //        manipulate that user interface once it has been created.
  46. //                                                
  47.  
  48. // ---------------------------------------------------------------------------
  49. // Special names and things like that
  50. //
  51. // "dirsForm": the name of the form which contains the directories UI
  52. // "filesForm": the name of the form which contains the files UI
  53. // 
  54.  
  55. // ---------------------------------------------------------------------------
  56. // Local procedures
  57. // 
  58.  
  59. //
  60. // Information about the various library UIs that exist in a given Maya session
  61. // will be stored in a lookup table which is represented by a carefully managed
  62. // string array. Stored in this array will be information such as the name of
  63. // the top level layout (referred to as the libraryUI), the visor objects
  64. // which are associated with the libraryUI, and the popup menu scripts used by
  65. // the files and directories displays.
  66. //
  67.  
  68. global string $gLibraryUILookupTable[];
  69. global int $gLibraryUILookupTableCreated = false;
  70.  
  71. proc createLibraryUILookupTable()
  72. {
  73.     //
  74.     // Description:
  75.     //    This procedure is called every time the user creates a libraryUI
  76.     //    component, but only has any effect the first time it is called.
  77.     //    This procedure initializes the string array $gLibraryUILookupTable[]
  78.     //    for use as a lookup table. The lookup table will contain information
  79.     //    about all libraryUI components which exist in the current Maya
  80.     //    session.
  81.     //
  82.  
  83.     global string $gLibraryUILookupTable[];
  84.     global int $gLibraryUILookupTableCreated;
  85.  
  86.     if (!$gLibraryUILookupTableCreated)
  87.     {
  88.         string $columns[];
  89.  
  90.         $columns[0] = "libraryUI";
  91.         $columns[1] = "directoriesVisorName";
  92.         $columns[2] = "filesVisorName";
  93.         $columns[3] = "directoriesPopupMenuScript";
  94.         $columns[4] = "filesPopupMenuScript";
  95.         $columns[5] = "currentDirectory";
  96.         $columns[6] = "rootDirectory";
  97.         $columns[7] = "filePressScript";
  98.         $columns[8] = "filePurpose";
  99.  
  100.         lookupTable($gLibraryUILookupTable, $columns);
  101.         $gLibraryUILookupTableCreated = true;
  102.     }
  103. }
  104.  
  105. proc registerLibraryUI(
  106.     string $libraryUI)
  107. {
  108.     //
  109.     // Description:
  110.     //    This procedure is used to register a libraryUI component by entering
  111.     //    it as a row in the lookup table which contains information about all
  112.     //    libraryUI components that currently exist in Maya.
  113.     //    The row created is initially blank except for the libraryUI name.
  114.     //    Further information about the libraryUI component must be
  115.     //    subsequently added to the lookup table.
  116.     //
  117.  
  118.     global string $gLibraryUILookupTable[];
  119.     string $row[];
  120.  
  121.     $row[0] = $libraryUI;
  122.     $row[1] = "";
  123.     $row[2] = "";
  124.     $row[3] = "";
  125.     $row[4] = "";
  126.     $row[5] = "";
  127.     $row[6] = "";
  128.     $row[7] = "";
  129.  
  130.     // Initially, all libraryUI should be created with a filePurpose of 
  131.     // "default"
  132.     // 
  133.     $row[8] = "default"; 
  134.  
  135.     lookupTableAddRow($gLibraryUILookupTable, $row);
  136. }
  137.  
  138. proc registerVisorNames(
  139.     string $libraryUI,
  140.     string $directoriesVisorName,
  141.     string $filesVisorName)
  142. {
  143.     //
  144.     // Description:
  145.     //    This procedure enters the $libraryUI, $directoriesVisorName and
  146.     //    $filesVisorName into a global array which is used as a lookup table to 
  147.     //    find a directories visor name given a library UI name.
  148.     //
  149.  
  150.     global string $gLibraryUILookupTable[];
  151.  
  152.     // ASSUMPTION:
  153.     // We assume that a row already exists for this libraryUI, as it should
  154.     // have been created by a call to registerLibraryUI() as the UI was being
  155.     // created.
  156.     //
  157.     lookupTableEdit(
  158.         $gLibraryUILookupTable,
  159.         "libraryUI",
  160.         $libraryUI,
  161.         "directoriesVisorName",
  162.         $directoriesVisorName);
  163.     lookupTableEdit(
  164.         $gLibraryUILookupTable,
  165.         "libraryUI",
  166.         $libraryUI,
  167.         "filesVisorName",
  168.         $filesVisorName);
  169. }
  170.  
  171. proc string lookupDirectoriesVisorName(
  172.     string $libraryUI)
  173. {
  174.     //
  175.     // Description:
  176.     //    This procedure looks through the global array being used as a lookup
  177.     //    table to find the directories visor name associated with the specified
  178.     //    library UI name.
  179.     //
  180.     // Returns: 
  181.     //    The directories visor name, if one is associated with the specified
  182.     //    library UI name.
  183.     //    Otherwise: "".
  184.     //
  185.  
  186.     global string $gLibraryUILookupTable[];
  187.  
  188.     return (lookupTableLookup(
  189.         $gLibraryUILookupTable,
  190.         "libraryUI",
  191.         $libraryUI,
  192.         "directoriesVisorName"));
  193. }
  194.  
  195. proc string generateUniqueDirectoriesVisorName()
  196. {
  197.     //
  198.     // Description:
  199.     //    This procedure is usually called just before creating a new directories
  200.     //    visor for a libraryUI.
  201.     //    This procedure generates a unique name for a directories visor by
  202.     //    creating a string of the form directories#VisorEd and incrementing the #
  203.     //    part until no visor by that name exists.
  204.     //
  205.     // Returns: 
  206.     //    A unique name by which a visor can be created.
  207.     //
  208.  
  209.     int $i = 1;
  210.     while (`hyperGraph -exists ("directories" + $i + "VisorEd")`)
  211.     {
  212.         $i++;
  213.     }
  214.     return ("directories" + $i + "VisorEd");
  215. }
  216.     
  217. proc string lookupFilesVisorName(
  218.     string $libraryUI)
  219. {
  220.     //
  221.     // Description:
  222.     //    This procedure looks through the global array being used as a lookup
  223.     //    table to find the files visor name associated with the specified
  224.     //    library UI name.
  225.     //
  226.     // Returns: 
  227.     //    The files visor name, if one is associated with the specified
  228.     //    library UI name.
  229.     //    Otherwise: "".
  230.     //
  231.  
  232.     global string $gLibraryUILookupTable[];
  233.  
  234.     return (lookupTableLookup(
  235.         $gLibraryUILookupTable,
  236.         "libraryUI",
  237.         $libraryUI,
  238.         "filesVisorName"));
  239. }
  240.  
  241. proc string generateUniqueFilesVisorName()
  242. {
  243.     //
  244.     // Description:
  245.     //    This procedure is usually called just before creating a new files
  246.     //    visor for a libraryUI.
  247.     //    This procedure generates a unique name for a files visor by
  248.     //    creating a string of the form files#VisorEd and incrementing the #
  249.     //    part until no visor by that name exists.
  250.     //
  251.     // Returns: 
  252.     //    A unique name by which a visor can be created.
  253.     //
  254.  
  255.     int $i = 1;
  256.     while (`hyperGraph -exists ("files" + $i + "VisorEd")`)
  257.     {
  258.         $i++;
  259.     }
  260.     return ("files" + $i + "VisorEd");
  261. }
  262.     
  263. proc registerFilePurpose(
  264.     string $libraryUI,
  265.     string $filePurpose)
  266. {
  267.     //
  268.     // Description:
  269.     //    This procedure enters the $filePurpose into a global array which is 
  270.     //    used as a lookup table to determine the purpose of the files contained
  271.     //    in a given library UI.
  272.     //
  273.     //    The file purpose is used as a sort of hint as to how the files are
  274.     //    going to be used. Currently, the following file purposes are valid:
  275.     //
  276.     //        "default": the directories are expected to contain standard files
  277.     //        such as images and maya files.
  278.     //        "brush": the directories are expected to contain paint effects
  279.     //        brush presets.
  280.     //
  281.  
  282.     if (
  283.             ($filePurpose != "default")
  284.         &&    ($filePurpose != "brush"))
  285.     {
  286.         error 
  287.             -showLineNumber true 
  288.             ("Unexpected file purpose string: " + $filePurpose);
  289.     }
  290.  
  291.     global string $gLibraryUILookupTable[];
  292.  
  293.     // ASSUMPTION:
  294.     // We assume that a row already exists for this libraryUI, as it should
  295.     // have been created by a call to registerLibraryUI() as the UI was being
  296.     // created.
  297.     //
  298.     lookupTableEdit(
  299.         $gLibraryUILookupTable,
  300.         "libraryUI",
  301.         $libraryUI,
  302.         "filePurpose",
  303.         $filePurpose);
  304. }
  305.  
  306. proc string lookupFilePurpose(
  307.     string $libraryUI)
  308. {
  309.     //
  310.     // Description:
  311.     //    This procedure looks through the global array being used as a lookup
  312.     //    table to find the file purpose string associated with the specified
  313.     //    library UI name.
  314.     //
  315.     // Returns: 
  316.     //    The file purpose string, if one is associated with the specified
  317.     //    library UI name.
  318.     //    Otherwise: "".
  319.     //
  320.  
  321.     global string $gLibraryUILookupTable[];
  322.  
  323.     return (lookupTableLookup(
  324.         $gLibraryUILookupTable,
  325.         "libraryUI",
  326.         $libraryUI,
  327.         "filePurpose"));
  328. }
  329.  
  330. // ---------------------------------------------------------------------------
  331. // Global procedures
  332. // 
  333. global proc string libraryUIFilesVisor(
  334.     string $libraryUI)
  335. {
  336.     //
  337.     // Description:
  338.     //    This procedure returns the name of the visor editor associated
  339.     //    with the specified libraryUI component.
  340.     //
  341.  
  342.     return lookupFilesVisorName($libraryUI);
  343. }
  344.  
  345. global proc string libraryUIDirectoriesVisor(
  346.     string $libraryUI)
  347. {
  348.     //
  349.     // Description:
  350.     //    This procedure returns the name of the visor editor associated
  351.     //    with the specified libraryUI component.
  352.     //
  353.  
  354.     return lookupDirectoriesVisorName($libraryUI);
  355. }
  356.  
  357. global proc libraryUIDirectoryPressed(
  358.     string $libraryUI,
  359.     string $oldCurrentDirectoryName,
  360.     string $editor,
  361.     string $dummy)
  362. {
  363.     //
  364.     // Description:
  365.     //    This procedure is called when the user left clicks on a directory in
  366.     //    the directories visor.
  367.     //    This procedure changes the currently selected directory in the
  368.     //    libraryUI, causing the files visor to update to show the contents of
  369.     //    the directory the user pressed on.
  370.     //
  371.  
  372.     // Not sure if this is a good approach to the whole problem of what
  373.     // directory is the current one. Perhaps it would be better to have the
  374.     // visor object have a sense of the current directory...
  375.     //
  376.     string $directoriesVisorName = lookupDirectoriesVisorName($libraryUI);
  377.     string $currentSelection[];
  378.     setParent $libraryUI;
  379.     $currentSelection = `visor -query -selectedGadgets $directoriesVisorName`;
  380.  
  381.     // Since it does not make much sense in this context for the user to be
  382.     // allowed to select multiple directories, we ignore all currently selected
  383.     // directories except the first one.
  384.     //
  385.     string $directory = $currentSelection[0];
  386.     libraryUISetCurrentDirectory(
  387.         $libraryUI,
  388.         $directory);
  389. }
  390.  
  391. // ---------------------------------------------------------------------------
  392. // Procedures to get and set the script to build the popup menu for the
  393. // directory visor.
  394. //
  395.  
  396. global proc string libraryUIDirectoriesPopupMenuScript(
  397.     string $libraryUI)
  398. {
  399.     //
  400.     // Description:
  401.     //    This procedure looks up the name of the popup menu script associated
  402.     //    with the directories visor of the specified libraryUI component.
  403.     //
  404.     // Returns: 
  405.     //    The name of the popup menu script.
  406.     //
  407.  
  408.     // Lookup the name of the directories popup menu script in the lookup table
  409.     //
  410.     global string $gLibraryUILookupTable[];
  411.  
  412.     return lookupTableLookup(
  413.         $gLibraryUILookupTable,
  414.         "libraryUI",
  415.         $libraryUI,
  416.         "directoriesPopupMenuScript");
  417. }
  418.  
  419. global proc libraryUISetDirectoriesPopupMenuScript(
  420.     string $libraryUI,
  421.     string $scriptName)
  422. {
  423.     //
  424.     // Description:
  425.     //    This procedure sets the popup menu script which is invoked when the
  426.     //    user RMB clicks in the directories visor of the specified libraryUI
  427.     //    component. The script will be called with two arguments: the name of
  428.     //    the visor editor from which the menu was invoked, and the name of
  429.     //    the popupMenu object to which the menu items are to be added.
  430.     //
  431.     //    If $scriptName is "", no popup menu will be invoked when the user RMB
  432.     //    clicks in the directories visor.
  433.     //
  434.  
  435.     // Find the name of the control that the menu will be attached to
  436.     //
  437.     string $directoriesVisorName = lookupDirectoriesVisorName($libraryUI);
  438.  
  439.     string $control    = `hyperGraph -query -control $directoriesVisorName`;
  440.     string $popupMenuName = ($directoriesVisorName + "PopupMenu");
  441.  
  442.     if ($scriptName == "")
  443.     {
  444.         if (`popupMenu -exists $popupMenuName`) 
  445.         {
  446.             deleteUI $popupMenuName;
  447.         }
  448.     }
  449.     else
  450.     {
  451.         // Create the popup menu
  452.         //    
  453.         if (!`popupMenu -exists $popupMenuName`) 
  454.         {
  455.             string $fullMenuName = `popupMenu -parent $control $popupMenuName`;
  456.             popupMenu 
  457.                 -edit
  458.                 -postMenuCommand 
  459.                     ($scriptName
  460.                         + " "
  461.                         + $directoriesVisorName 
  462.                         + " " 
  463.                         + $popupMenuName)
  464.                 $fullMenuName;    
  465.         }
  466.     }
  467.  
  468.     // Store the name of the directories popup menu script in the lookup table
  469.     // 
  470.     // ASSUMPTION:
  471.     // We assume that a row already exists for this libraryUI, as it should
  472.     // have been created by a call to registerLibraryUI() as the UI was being
  473.     // created.
  474.     //
  475.     global string $gLibraryUILookupTable[];
  476.  
  477.     lookupTableEdit(
  478.         $gLibraryUILookupTable,
  479.         "libraryUI",
  480.         $libraryUI,
  481.         "directoriesPopupMenuScript",
  482.         $scriptName);
  483. }
  484.  
  485. // ---------------------------------------------------------------------------
  486. // Procedures to get and set the script to build the popup menu for the
  487. // files visor.
  488. //
  489.  
  490. global proc string libraryUIFilesPopupMenuScript(
  491.     string $libraryUI)
  492. {
  493.     //
  494.     // Description:
  495.     //    This procedure looks up the name of the popup menu script associated
  496.     //    with the files visor of the specified libraryUI component.
  497.     //
  498.     // Returns: 
  499.     //    The name of the popup menu script.
  500.     //
  501.  
  502.     // Lookup the name of the files popup menu script in the lookup table
  503.     //
  504.     global string $gLibraryUILookupTable[];
  505.  
  506.     return lookupTableLookup(
  507.         $gLibraryUILookupTable,
  508.         "libraryUI",
  509.         $libraryUI,
  510.         "filesPopupMenuScript");
  511. }
  512.  
  513. global proc libraryUISetFilesPopupMenuScript(
  514.     string $libraryUI,
  515.     string $scriptName)
  516. {
  517.     //
  518.     // Description:
  519.     //    This procedure sets the popup menu script which is invoked when the
  520.     //    user RMB clicks in the files visor of the specified libraryUI
  521.     //    component. The script will be called with two arguments: the name of
  522.     //    the visor editor from which the menu was invoked, and the name of
  523.     //    the popupMenu object to which the menu items are to be added.
  524.     //
  525.     //    If $scriptName is "", no popup menu will be invoked when the user RMB
  526.     //    clicks in the files visor.
  527.     //
  528.  
  529.     // Find the name of the control that the menu will be attached to
  530.     //
  531.     string $filesVisorName     = lookupFilesVisorName($libraryUI);
  532.  
  533.     string $control            = `hyperGraph -query -control $filesVisorName`;
  534.     string $popupMenuName    = ($filesVisorName + "PopupMenu");
  535.  
  536.     if ($scriptName == "")
  537.     {
  538.         if (`popupMenu -exists $popupMenuName`) 
  539.         {
  540.             deleteUI $popupMenuName;
  541.         }
  542.     }
  543.     else
  544.     {
  545.         // Create the popup menu
  546.         //    
  547.         if (!`popupMenu -exists $popupMenuName`) 
  548.         {
  549.             string $fullMenuName = `popupMenu -parent $control $popupMenuName`;
  550.             popupMenu 
  551.                 -edit
  552.                 -postMenuCommand 
  553.                     ($scriptName
  554.                         + " "
  555.                         + $filesVisorName 
  556.                         + " " 
  557.                         + $popupMenuName)
  558.                 $fullMenuName;    
  559.         }
  560.     }
  561.  
  562.     // Store the name of the files popup menu script in the lookup table
  563.     // 
  564.     // ASSUMPTION:
  565.     // We assume that a row already exists for this libraryUI, as it should
  566.     // have been created by a call to registerLibraryUI() as the UI was being
  567.     // created.
  568.     //
  569.     global string $gLibraryUILookupTable[];
  570.  
  571.     lookupTableEdit(
  572.         $gLibraryUILookupTable,
  573.         "libraryUI",
  574.         $libraryUI,
  575.         "filesPopupMenuScript",
  576.         $scriptName);
  577. }
  578.  
  579. global proc string libraryUIFilePressScript(
  580.     string $libraryUI)
  581. {
  582.     //
  583.     // Description:
  584.     //    This procedure determines the name of the script which is called when
  585.     //    the user left clicks on a file in the files visor of the libraryUI. The
  586.     //    name is determined by looking it up in the lookup table.
  587.     //
  588.     // Returns: 
  589.     //    The script which is called when the user left clicks on a file in the
  590.     //    files visor of this libraryUI.
  591.     //
  592.  
  593.     // Lookup the name of the file press menu script in the lookup table
  594.     //
  595.     global string $gLibraryUILookupTable[];
  596.  
  597.     return lookupTableLookup(
  598.         $gLibraryUILookupTable,
  599.         "libraryUI",
  600.         $libraryUI,
  601.         "filePressScript");
  602. }
  603.  
  604. global proc libraryUISetFilePressScript(
  605.     string $libraryUI,
  606.     string $script)
  607. {
  608.     //
  609.     // Description:
  610.     //    This procedure sets the script to be called when the user left clicks 
  611.     //    on a file in the files visor of the libraryUI. The name is also stored 
  612.     //    in the lookup table.
  613.     //
  614.  
  615.     // Find the name of the editor that the script will be registered with
  616.     //
  617.     string $filesVisorName     = lookupFilesVisorName($libraryUI);
  618.  
  619.     hyperGraph
  620.         -edit
  621.         -nodePressCommand $script
  622.         $filesVisorName;
  623.  
  624.     // Store the name of the file node press script in the lookup table
  625.     // 
  626.     // ASSUMPTION:
  627.     // We assume that a row already exists for this libraryUI, as it should
  628.     // have been created by a call to registerLibraryUI() as the UI was being
  629.     // created.
  630.     //
  631.     global string $gLibraryUILookupTable[];
  632.  
  633.     lookupTableEdit(
  634.         $gLibraryUILookupTable,
  635.         "libraryUI",
  636.         $libraryUI,
  637.         "filePressScript",
  638.         $script);
  639. }
  640.  
  641. global proc int libraryUIIsManaged(
  642.     string $libraryUI)
  643. {
  644.     //
  645.     // Description:
  646.     //    This procedure is used to query whether the overall layout of the
  647.     //    specified libraryUI component is managed or not. 
  648.     //
  649.     // Returns: 
  650.     //    This procedure returns true if the overall layout is managed, false if
  651.     //    not.
  652.     //
  653.  
  654.     return `paneLayout -query -manage $libraryUI`;
  655. }
  656.  
  657. global proc libraryUIManage(
  658.     string $libraryUI,
  659.     int $manage)
  660. {
  661.     //
  662.     // Description:
  663.     //    This procedure lets the caller manage or unmanage the overall layout of
  664.     //    the specified libraryUI component.
  665.     //
  666.  
  667.     paneLayout -edit -manage $manage $libraryUI;
  668. }
  669.  
  670. global proc string[] libraryUICurrentlySelectedFiles(
  671.     string $libraryUI)
  672. {
  673.     //
  674.     // Description:
  675.     //    This procedure determines the currently selected files within the files
  676.     //    visor of the specified libraryUI.
  677.     //
  678.     // Returns: 
  679.     //    A list of the currently selected files with in the files visor of the
  680.     //    specified libraryUI.
  681.     //
  682.  
  683.     string $filesVisorName = lookupFilesVisorName($libraryUI);
  684.     string $currentSelection[];
  685.     setParent $libraryUI;
  686.     $currentSelection = `visor -query -selectedGadgets $filesVisorName`;
  687.     return $currentSelection;
  688. }
  689.  
  690. global proc int libraryUIDirectoriesShown(
  691.     string $libraryUI)
  692. {
  693.     //
  694.     // Description:
  695.     //    This procedure determines whether the directories visor of the
  696.     //    libraryUI is being displayed.
  697.     //
  698.     // Returns: 
  699.     //    True if the directories visor is being displayed, false otherwise (ie
  700.     //    the libraryUI is showing only files).
  701.     //
  702.  
  703.     int $rShown = false;
  704.  
  705.     string $configuration;
  706.     string $firstPane;
  707.     string $dirsForm;
  708.  
  709.     setParent $libraryUI;
  710.  
  711.     // ASSUMPTION: This code assumes that $libraryUI is the name of the 
  712.     // paneLayout, which is currently true. 
  713.     //
  714.     string $dirsAndFilesPane = $libraryUI;
  715.     $configuration = `paneLayout -query -configuration $dirsAndFilesPane`;
  716.     $firstPane = `paneLayout -query -pane1 $dirsAndFilesPane`;
  717.     $firstPane = `setParent $firstPane`;
  718.  
  719.     setParent $libraryUI;
  720.     $dirsForm = `setParent dirsForm`;
  721.  
  722.     if ($configuration == "vertical2")
  723.     {
  724.         // Both panes are being shown, therefore files are being shown.
  725.         //
  726.         $rShown = true;
  727.     }
  728.     else if (($configuration == "single") && ($firstPane == $dirsForm))
  729.     {
  730.         // Only one pane is being shown, and it is the directories.
  731.         //
  732.         $rShown = true;
  733.     }
  734.     return $rShown;
  735. }
  736.  
  737. global proc int libraryUIFilesShown(
  738.     string $libraryUI)
  739. {
  740.     //
  741.     // Description:
  742.     //    This procedure determines whether the files visor of the
  743.     //    libraryUI is being displayed.
  744.     //
  745.     // Returns: 
  746.     //    True if the files visor is being displayed, false otherwise (ie
  747.     //    the libraryUI is showing only directories).
  748.     //
  749.  
  750.     int $rShown = false;
  751.  
  752.     string $configuration;
  753.     string $firstPane;
  754.     string $filesForm;
  755.  
  756.     setParent $libraryUI;
  757.  
  758.     // ASSUMPTION: This code assumes that $libraryUI is the name of the 
  759.     // paneLayout, which is currently true. 
  760.     //
  761.     string $dirsAndFilesPane = $libraryUI;
  762.     $configuration = `paneLayout -query -configuration $dirsAndFilesPane`;
  763.     $firstPane = `paneLayout -query -pane1 $dirsAndFilesPane`;
  764.     $firstPane = `setParent $firstPane`;
  765.  
  766.     setParent $libraryUI;
  767.     $filesForm = `setParent filesForm`;
  768.  
  769.     if ($configuration == "vertical2")
  770.     {
  771.         // Both panes are being shown, therefore files are being shown.
  772.         //
  773.         $rShown = true;
  774.     }
  775.     else if (($configuration == "single") && ($firstPane == $filesForm))
  776.     {
  777.         // Only one pane is being shown, and it is the files.
  778.         //
  779.         $rShown = true;
  780.     }
  781.     return $rShown;
  782. }
  783.  
  784. global proc libraryUIShowDirectoriesOnly(
  785.     string $libraryUI)
  786. {
  787.     //
  788.     // Description:
  789.     //    This procedure causes the specified libraryUI to modify its layout such
  790.     //    that the pane containing the files visor is hidden and the pane
  791.     //    containing the directories takes up the full area of the layout.
  792.     //
  793.  
  794.     // ASSUMPTION: This code assumes that $libraryUI is the name of the 
  795.     // paneLayout, which is currently true. 
  796.     //
  797.     string $dirsAndFilesPane = $libraryUI;
  798.     paneLayout
  799.         -edit
  800.         -configuration "single"
  801.         -setPane dirsForm 1
  802.         $dirsAndFilesPane;
  803. }
  804.  
  805. global proc libraryUIShowFilesOnly(
  806.     string $libraryUI)
  807. {
  808.     //
  809.     // Description:
  810.     //    This procedure causes the specified libraryUI to modify its layout such
  811.     //    that the pane containing the directories visor is hidden and the pane
  812.     //    containing the files takes up the full area of the layout.
  813.     //
  814.  
  815.     // ASSUMPTION: This code assumes that $libraryUI is the name of the 
  816.     // paneLayout, which is currently true. 
  817.     //
  818.     string $dirsAndFilesPane = $libraryUI;
  819.     paneLayout
  820.         -edit
  821.         -configuration "single"
  822.         -setPane filesForm 1
  823.         $dirsAndFilesPane;
  824. }
  825.  
  826. global proc libraryUIShowDirectoriesAndFiles(
  827.     string $libraryUI)
  828. {
  829.     //
  830.     // Description:
  831.     //    This procedure causes the specified libraryUI to modify its layout such
  832.     //    that the both the pane containing the directories visor and the pane
  833.     //    containing the files visor are visible.
  834.     //
  835.  
  836.     // ASSUMPTION: This code assumes that $libraryUI is the name of the 
  837.     // paneLayout, which is currently true. 
  838.     //
  839.     string $dirsAndFilesPane = $libraryUI;
  840.     paneLayout
  841.         -edit
  842.         -configuration "vertical2"
  843.         -setPane dirsForm 1
  844.         -setPane filesForm 2
  845.         $dirsAndFilesPane;
  846. }
  847.  
  848. global proc string libraryUICurrentDirectory(
  849.     string $libraryUI)
  850. {
  851.     //
  852.     // Description:
  853.     //    This method determines the current directory of the specified
  854.     //    libraryUI.
  855.     //
  856.     // Returns: 
  857.     //    The name of the current directory.
  858.     //
  859.  
  860.     global string $gLibraryUILookupTable[];
  861.  
  862.     return lookupTableLookup(
  863.         $gLibraryUILookupTable,
  864.         "libraryUI",
  865.         $libraryUI,
  866.         "currentDirectory");
  867. }
  868.  
  869. global proc libraryUIUseForPaintEffects(
  870.     string $libraryUI)
  871. {
  872.     //
  873.     // Description:
  874.     //    This procedure is called when the libraryUI has been created for the
  875.     //    purpose of providing access to paint effects brushes.
  876.     //    This procedure sets the filePurpose of the specified libraryUI
  877.     //    component to "brush", which indicates that the files contained in
  878.     //    directories to be shown in the libraryUI are expected to be paint
  879.     //    effects brush presets.
  880.     //
  881.  
  882.     registerFilePurpose($libraryUI, "brush");
  883. }
  884.  
  885. proc int libraryUIIsUsedForPaintEffects(
  886.     string $libraryUI)
  887. {
  888.     //
  889.     // Description:
  890.     //    This procedure returns true if the filePurpose of the specified
  891.     //    libraryUI is "brush", an indication that files contained in the
  892.     //    directories shown in the libraryUI are expected to be paint effects
  893.     //    brush presets.
  894.     //
  895.  
  896.     return (lookupFilePurpose($libraryUI) == "brush");
  897. }
  898.  
  899. global proc libraryUISetCurrentDirectory(
  900.     string $libraryUI,
  901.     string $directoryName)
  902. {
  903.     //
  904.     // Description:
  905.     //    This method sets the current directory of the specified
  906.     //    libraryUI.
  907.     //
  908.  
  909.     string $filesVisorName = lookupFilesVisorName($libraryUI);
  910.  
  911.     setParent $libraryUI;
  912.     setParent filesForm;
  913.  
  914.     visor 
  915.         -reset 
  916.         $filesVisorName;
  917.  
  918.     // We set the characteristics of the visor here because the -reset flag
  919.     // causes many of them to be returned to their default values.
  920.     //
  921.     visor 
  922.         -showDividers false
  923.         -showFolders false
  924.         -showFiles true
  925.         -showNodes false
  926.         -allowPanningInX true
  927.         -allowPanningInY true
  928.         -allowZooming true
  929.         -restrictPanAndZoom false
  930.         $filesVisorName;
  931.  
  932.     if (libraryUIIsUsedForPaintEffects($libraryUI))
  933.     {
  934.         // Create the folder so that the controls it contains are specifically
  935.         // tailored to Paint Effects. In particular, users should be able to
  936.         // drag and drop the brush to a shelf. If we were to create visor
  937.         // folders the same way that we create folders for normal directories,
  938.         // you would be unable to drag and drop the brush to the shelf.
  939.         //
  940.         visor 
  941.             -addFolder 
  942.             -openDirectories false
  943.             -openFolder true
  944.             -type shelfItems 
  945.             -cmd $directoryName
  946.             -name "Brushes"
  947.             $filesVisorName;
  948.     }
  949.     else
  950.     {
  951.         // Create the folder as a folder to contain ordinary files. 
  952.         //
  953.         visor 
  954.             -addFolder 
  955.             -openDirectories false
  956.             -openFolder true
  957.             -type directory 
  958.             -path $directoryName
  959.             -name $directoryName
  960.             $filesVisorName;
  961.     }
  962.     
  963.     visor
  964.         -rebuild
  965.         $filesVisorName;
  966.  
  967.     hyperGraph
  968.         -edit
  969.         -frameGraph
  970.         $filesVisorName;
  971.  
  972.     global string $gLibraryUILookupTable[];
  973.  
  974.     lookupTableEdit(
  975.         $gLibraryUILookupTable,
  976.         "libraryUI",
  977.         $libraryUI,
  978.         "currentDirectory",
  979.         $directoryName);
  980. }
  981.  
  982. global proc string libraryUIRootDirectory(
  983.     string $libraryUI)
  984. {
  985.     //
  986.     // Description:
  987.     //    This method determines the root directory of the specified
  988.     //    libraryUI.
  989.     //
  990.     // Returns: 
  991.     //    The name of the root directory.
  992.     //
  993.  
  994.     global string $gLibraryUILookupTable[];
  995.  
  996.     return lookupTableLookup(
  997.         $gLibraryUILookupTable,
  998.         "libraryUI",
  999.         $libraryUI,
  1000.         "rootDirectory");
  1001. }
  1002.  
  1003. global proc libraryUISetRootDirectory(
  1004.     string $libraryUI,
  1005.     string $directoryName)
  1006. {
  1007.     //
  1008.     // Description:
  1009.     //    This method sets the root directory of the specified
  1010.     //    libraryUI.
  1011.     //    In doing so, this procedure also sets the current directory to the same
  1012.     //    directory.
  1013.     //
  1014.  
  1015.     string $directoriesVisorName = lookupDirectoriesVisorName($libraryUI);
  1016.     setParent $libraryUI;
  1017.     setParent dirsForm;
  1018.     visor 
  1019.         -reset 
  1020.         $directoriesVisorName;
  1021.  
  1022.     // We set the characteristics of the visor here because the -reset flag
  1023.     // causes many of them to be returned to their default values.
  1024.     //
  1025.     visor 
  1026.         -showDividers false
  1027.         -showFiles false
  1028.         -showNodes false
  1029.         -allowPanningInX false
  1030.         -allowZooming false
  1031.         -restrictPanAndZoom true
  1032.         -popupMenuScript ""
  1033.         $directoriesVisorName;
  1034.  
  1035.     visor 
  1036.         -addFolder 
  1037.         -openDirectories true
  1038.         -type directory 
  1039.         -path $directoryName
  1040.         -name $directoryName
  1041.         $directoriesVisorName;
  1042.  
  1043.     hyperGraph
  1044.         -edit
  1045.         -zoom 0.2
  1046.         $directoriesVisorName;
  1047.  
  1048.     libraryUISetCurrentDirectory($libraryUI, $directoryName);
  1049.  
  1050.     global string $gLibraryUILookupTable[];
  1051.  
  1052.     lookupTableEdit(
  1053.         $gLibraryUILookupTable,
  1054.         "libraryUI",
  1055.         $libraryUI,
  1056.         "rootDirectory",
  1057.         $directoryName);
  1058. }
  1059.  
  1060. global proc libraryUISaveSwatchesToDisk(
  1061.     string $libraryUI)
  1062. {
  1063.     //
  1064.     // Description:
  1065.     //    This procedure saves the currently displayed swatches as .swatch files 
  1066.     //    on disk. This allows the swatches to be loaded much more quickly when 
  1067.     //    the same directory is viewed in the future.
  1068.     //
  1069.  
  1070.     string $filesVisor;
  1071.     $filesVisor = lookupFilesVisorName($libraryUI);
  1072.     
  1073.     visor -saveSwatches $filesVisor;
  1074. }
  1075.  
  1076. global proc libraryUIRefreshFileListing(
  1077.     string $libraryUI)
  1078. {
  1079.     //
  1080.     // Description:
  1081.     //    This procedure causes the set of files displayed in the visor to be
  1082.     //    updated, so that files that have been added to the directory will
  1083.     //    appear and files which have been removed from the directory will
  1084.     //    disappear.
  1085.     //
  1086.  
  1087.     string $filesVisor;
  1088.     $filesVisor = lookupFilesVisorName($libraryUI);
  1089.  
  1090.     visor -rebuild $filesVisor;
  1091.  
  1092.     string $directoriesVisor;
  1093.     $directoriesVisor = lookupDirectoriesVisorName($libraryUI);
  1094.  
  1095.     visor -rebuild $directoriesVisor;
  1096. }
  1097.  
  1098. global proc libraryUIRefreshSelectedSwatches(
  1099.     string $libraryUI)
  1100. {
  1101.     //
  1102.     // Description:
  1103.     //    This procedure causes all of the swatches of selected files to be
  1104.     //    refreshed to reflect changes made to those files.
  1105.     //
  1106.  
  1107.     string $filesVisor;
  1108.     $filesVisor = lookupFilesVisorName($libraryUI);
  1109.  
  1110.     waitCursor -state on;
  1111.  
  1112.     visor -refreshSelectedSwatches $filesVisor;
  1113.  
  1114.     waitCursor -state off;
  1115. }
  1116.  
  1117. global proc libraryUIRefreshAllSwatches(
  1118.     string $libraryUI)
  1119. {
  1120.     //
  1121.     // Description:
  1122.     //    This procedure causes the swatches of all of the currently displayed 
  1123.     //    files to be refreshed to reflect any changes made to those files.
  1124.     //
  1125.  
  1126.     string $filesVisor;
  1127.     $filesVisor = lookupFilesVisorName($libraryUI);
  1128.  
  1129.     waitCursor -state on;
  1130.  
  1131.     visor -refreshAllSwatches $filesVisor;
  1132.  
  1133.     waitCursor -state off;
  1134. }
  1135.  
  1136. // ---------------------------------------------------------------------------
  1137. // Procedures for creating and deleting a library UI
  1138. // 
  1139.  
  1140. global proc libraryUIDelete(
  1141.     string $libraryUI,
  1142.     int $alsoDeleteVisors)
  1143. {
  1144.     //
  1145.     // Description:
  1146.     //    This procedure deletes all UI associated with the specified
  1147.     //    libraryUI component. 
  1148.     //    If $alsoDeleteVisors is true, the visor editors associated
  1149.     //    with the libraryUI component are also deleted. If
  1150.     //    $alsoDeleteVisors is false, the visor editors are simply
  1151.     //    unparented from the layout and will persist after the layout has been
  1152.     //    deleted. Typically you would want to do this if you were deleting
  1153.     //    the libraryUI component but planned to create an identical new one.
  1154.     //    By not deleting the visor editors, you will be able to reparent
  1155.     //    them to the new libraryUI component, hence preserving the state of
  1156.     //    things being displayed by that editor. See the description in
  1157.     //    libraryUI() for more details.
  1158.     //
  1159.  
  1160.     if (!$alsoDeleteVisors)
  1161.     {
  1162.         // The caller has asked us not to delete the visor objects along with
  1163.         // the UI, so we unparent them from the UI before we delete the UI.
  1164.         //
  1165.         string $directoriesVisorName = lookupDirectoriesVisorName($libraryUI);
  1166.         string $filesVisorName = lookupFilesVisorName($libraryUI);
  1167.         hyperGraph -edit -unParent $directoriesVisorName;
  1168.         hyperGraph -edit -unParent $filesVisorName;
  1169.     }
  1170.  
  1171.     deleteUI $libraryUI;
  1172. }
  1173.  
  1174. global proc string libraryUI(
  1175.     string $parentFormLayout,
  1176.     string $directoriesVisorName,
  1177.     string $filesVisorName)
  1178. {
  1179.     //
  1180.     // Description:
  1181.     //    This method is called from any piece of UI which wants to create a
  1182.     //    libraryUI within itself. 
  1183.     //    This method creates the library UI.
  1184.     //    If the directoriesVisorName and filesVisorName are specified, the UI 
  1185.     //    will use visor objects by those names for the directories display and 
  1186.     //    the    files display. In particular, this is designed to allow the library
  1187.     //    UI to be moved from layout to layout without dramatically changing its
  1188.     //    appearance. Otherwise (if directoriesVisorName and filesVisorName are
  1189.     //    ""), new visor objects will be created.
  1190.     //
  1191.     // Returns: 
  1192.     //    This method returns the name of the UI which should be stored by the
  1193.     //    caller for later use in performing operations on the library UI.
  1194.     //
  1195.  
  1196.     // Create the library UI lookup table if it doesn't already exist.
  1197.     //
  1198.     createLibraryUILookupTable();
  1199.  
  1200.     string $libraryUI;
  1201.  
  1202.     //
  1203.     // Create the directories and files UI
  1204.     //
  1205.  
  1206.     $libraryUI = `paneLayout 
  1207.         -configuration "vertical2"
  1208.         -paneSize 1 30 100
  1209.         dirsAndFilesPane`;
  1210.  
  1211.         if ($directoriesVisorName == "")
  1212.         {
  1213.             $directoriesVisorName = generateUniqueDirectoriesVisorName();
  1214.             hyperGraph -unParent $directoriesVisorName;
  1215.         }
  1216.  
  1217.         if ($filesVisorName == "")
  1218.         {
  1219.             $filesVisorName = generateUniqueFilesVisorName();
  1220.             hyperGraph -unParent $filesVisorName;
  1221.         }
  1222.  
  1223.         registerLibraryUI($libraryUI);
  1224.         registerVisorNames($libraryUI, $directoriesVisorName, $filesVisorName);
  1225.  
  1226.         // Create a form layout to contain the directories UI. This form 
  1227.         // layout must be called "dirsForm" because other UI will need to 
  1228.         // be able to find it by name later on.
  1229.         //
  1230.         formLayout dirsForm;
  1231.             hyperGraph 
  1232.                 -edit
  1233.                 -unParent $directoriesVisorName;
  1234.             hyperGraph 
  1235.                 -edit 
  1236.                 -parent dirsForm 
  1237.                 $directoriesVisorName;
  1238.             string $scrollBar = 
  1239.                 `floatScrollBar
  1240.                     -parent dirsForm
  1241.                     -horizontal false
  1242.                     -width 20
  1243.                     scrollBar`;
  1244.             floatScrollBar
  1245.                 -edit
  1246.                 -dragCommand 
  1247.                     ("visor -scrollPercent "
  1248.                         + "`floatScrollBar -query -value "
  1249.                         + $scrollBar
  1250.                         + "` "
  1251.                         + $directoriesVisorName)
  1252.                 $scrollBar;
  1253.             floatScrollBar
  1254.                 -edit
  1255.                 -changeCommand 
  1256.                     ("visor -scrollPercent "
  1257.                         + "`floatScrollBar -query -value "
  1258.                         + $scrollBar
  1259.                         + "` "
  1260.                         + $directoriesVisorName)
  1261.                 $scrollBar;
  1262.             visor
  1263.                 -scrollBar $scrollBar
  1264.                 $directoriesVisorName;
  1265.                     
  1266.             formLayout 
  1267.                 -edit
  1268.                 -af $directoriesVisorName top    0
  1269.                 -af $directoriesVisorName bottom 0
  1270.                 -af $directoriesVisorName left    0
  1271.                 -ac $directoriesVisorName right    0 $scrollBar
  1272.  
  1273.                 -af $scrollBar top 0
  1274.                 -af $scrollBar bottom 0
  1275.                 -an $scrollBar left
  1276.                 -af $scrollBar right 0
  1277.                 dirsForm;
  1278.         setParent ..; // from dirsForm
  1279.  
  1280.         // Create a form layout to contain the files UI. This form 
  1281.         // layout must be called "filesForm" because other UI will 
  1282.         // need to be able to find it by name later on.
  1283.         //
  1284.         formLayout filesForm;
  1285.             hyperGraph 
  1286.                 -edit
  1287.                 -unParent 
  1288.                 $filesVisorName;
  1289.             hyperGraph 
  1290.                 -edit 
  1291.                 -parent filesForm 
  1292.                 $filesVisorName;
  1293.             formLayout 
  1294.                 -edit
  1295.                 -af $filesVisorName top 0
  1296.                 -af $filesVisorName bottom 0
  1297.                 -af $filesVisorName left 0
  1298.                 -af $filesVisorName right 0
  1299.                 filesForm;
  1300.         setParent ..; // from filesForm
  1301.     setParent ..; // from dirsAndFilesPane 
  1302.  
  1303.     if ($directoriesVisorName == "")
  1304.     {
  1305.         $directoriesVisorName = lookupDirectoriesVisorName($libraryUI);
  1306.     }
  1307.  
  1308.     hyperGraph 
  1309.         -edit 
  1310.         -directoryPressCommand 
  1311.             ("libraryUIDirectoryPressed " + $libraryUI + "\"\"")
  1312.         $directoriesVisorName;
  1313.  
  1314.     formLayout 
  1315.         -edit
  1316.         -af $libraryUI top         0
  1317.         -af $libraryUI bottom   0
  1318.         -af $libraryUI left     0
  1319.         -af $libraryUI right     0
  1320.         $parentFormLayout;
  1321.  
  1322.     return $libraryUI;
  1323. }
  1324.  
  1325.